var wxbLogin=wxbLogin||{},wxb='',wxbAdmin=wxbAdmin||{};
var cPath='/Cyberspace/dev/';
wxbLogin.login={
    i:function(){
        fui.use(['JsForm','layer'],function(){})
    },
    btn:{
        login:function(){
            JsForm('.login-form').submit(function(r){
                if(r.code==1){
                    wxbData.login(r.result,function(){
                        sessionStorage.setItem('adminData',1);
                        location.href=cPath+'admin.html'
                    })
                }else{
                    layer.msg(r.msg)
                }
            });
        }
    }
};
wxbLogin.login.i();

JsRouter.map([
    {
        'path':'/index',
        'join':'wxbAdmin.org.i',
        'back':'wxbAdmin.org.i'
    }
]);
JsRouter.render();
wxbAdmin.init={
    e:{
        $:''
    },
    com:{
        isOk:function(c){
            var poll=function(){
                if(!wxbAdmin.init.e.$){
                    setTimeout(poll,20)
                }else{
                    c?c():'';
                }
            };
            poll();
        },
        toggle:function(e,className){
            var $=wxbAdmin.init.e.$;
            if($(e).hasClass(className)){
                $(e).removeClass(className)
            }else{
                $(e).addClass(className)
            }
        },
        menu:function(m){
            wxbAdmin.init.e.$('.aside-menu [data-menu="'+m+'"]').addClass('active').siblings().removeClass('active');
        }
    },
    load:function(){
        var _t=this;
        if(!sessionStorage.getItem('adminData')) return location.href=cPath+'login.html';
        fui.use(['JsPage','JsTpl','layer'],function(){
            wxbAdmin.init.e.$=fui.$;
            _t.btn.i();
            var wh=fui.$(window).height();
            wh=wh-5>710?wh-5:710;
            fui.$('.main-box').css('height',wh);
            JsForm().skin();
        });
    },
    btn:{
        i:function(){
            var $=wxbAdmin.init.e.$,body=$('body'),header=$('.header');
            header.hover(function(){
                header.addClass('hover')
            },function(){
                $('.header-user').removeClass('active');
                header.removeClass('hover')
            });
            body.on('click',function(){
                $('.header-user').removeClass('active');
            });
            this.resize();
        },
        userShow:function(){
            fui.stope();
            wxbAdmin.init.e.$('.header-user').addClass('active');
        },
        resize:function(){
            wxbAdmin.init.e.$(window).resize(function() {
                var $=wxbAdmin.init.e.$;
                var wh=$(window).height();
                wh=wh-5>710?wh-5:710;
                wxbAdmin.init.e.$('.main-box').css('height',wh);
            });
        },
        editPassword:function(){
            var $=wxbAdmin.init.e.$;
            layer.open({
                title:'修改密码',
                content:$('#passwordBox').html(),
                btn:['确定','取消'],
                yes:function(){
                    JsForm('.editForm').submit(function(r){
                        if(r.code==1){
                            wxbData.rePassword(r.result)
                        }else{
                            layer.msg(r.msg)
                        }
                    })
                }
            })
        }
    }
};
//管理员
wxbAdmin.org={
    d:{},
    i:function(){
        wxbAdmin.init.com.isOk(function(){
            wxbAdmin.org.load();
        })
    },
    load:function(){
        wxbAdmin.init.com.menu('org');
        var $=wxbAdmin.init.e.$;
        $('.mod-main').empty().append($('#orgBox').html());
        wxbData.getRoleList(function(r){

        });
        wxbAdmin.org.com(1);
    },
    com:function(oid){
        wxbData.getOrgList(oid,function(r){
            console.log(r)
        })
    },
    btn:{
        toUpdate:function(){//同步
            wxbData.orgUpdate(function(){
                wxbAdmin.org.com(1);
            })
        },
        toAdd:function(){
            if(wxbAdmin.org.d.isUpdate){

            }else{
                layer.msg('请先选择组织以后,在分配角色')
            }
        }
    }
};

